#ifndef DBSYSTEMLOG_H
#define DBSYSTEMLOG_H

#pragma once

#include <QSharedPointer>
#include <QVector>

namespace ns_yht
{
    namespace SystemEventType
    {
        const int turnOn = 0;
        const int turnOff = 1;
    }

    struct ModelSystemLog
    {
        int id;
        qint64 stime;
        int stype; // SystemEventType
        QString remark;

        QString typeName() const
        {
            if (stype == SystemEventType::turnOn)
                return "开机";
            else
                return "关机";
        }
    };

    class DbSystemLog
    {
    public:
        DbSystemLog();
        ~DbSystemLog();

        bool getList(QVector<QSharedPointer<ModelSystemLog>> &modelList);
        bool getList(QVector<QSharedPointer<ModelSystemLog>> &modelList, qint64 startTime, qint64 endTime);
        bool getList_page(QVector<QSharedPointer<ModelSystemLog>> &modelList, int pageIndex, int pageSize);
        bool getUnPostedList(QVector<QSharedPointer<ModelSystemLog>> &modelList);
        bool updatePosted();
        bool save(qint64 stime, int stype, QString remark, bool posted);
        bool removeBefore(qint64 ctime);
        int getCount();

    private:
        bool checkTable();

        bool tableOk = false;
    };

} // namespace ns_yht
#endif